package com.weavernorth.retailExperienceAward.service;

import com.weavernorth.retailExperienceAward.dto.dpxxInfo;
import com.weavernorth.retailExperienceAward.dto.dpxxVo;
import com.weavernorth.util.Logger4jUtil;
import com.weavernorth.util.dateUtils;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.log4j.Logger;
import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.workflow.webservices.*;

//import javax.ejb.Init;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @Author: bruseewang
 * @Package: com.weavernorth.retailExperienceAward.service
 * @date: 2020/6/1 16:15
 * @description: 定时任务：店铺零售体验考核申请流程-店长
 */
public class StoreRetailExpService {
//    private static Log log = LogFactory.getLog(StoreRetailExpService.class);
    public Logger log;
    public Logger getLog() {
        return log;
    }
    public void setLog(Logger log) {
        this.log = log;
    }
    public Integer cycle;
    public Integer getcycle() {
        return cycle;
    }
    public void setcycle(Integer cycle) {
        this.cycle = cycle;
    }
    /***
     * 创建流程
     */
    public void createFormal() {
        log.info("定时任务：店铺零售体验考核申请流程-店长");
        String strCreator = "1";//31299:周艳梅
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        String strJcrq = df.format(new Date());
        String strKhzq=dateUtils.previousMonth(0);//本周期
        if (cycle!=null){
            strKhzq= dateUtils.previousMonth(cycle);
        }
        String strKhzq_pre=dateUtils.previousMonth(strKhzq);//上周期
        RecordSet rs_getZfs_avg=new RecordSet();//获取上店铺总分数的平均分
        String strSql="SELECT ROUND(AVG(zfs), 2) as zf_avg FROM uf_qyjlpf where khzq='"+strKhzq_pre+"' GROUP BY khzq";
        String strGetAvg="";//平均分
        String strYybzfs="";//营运标准分
        rs_getZfs_avg.executeQuery(strSql);
        while (rs_getZfs_avg.next()){
            strGetAvg=Util.null2String(rs_getZfs_avg.getString("zf_avg"));
        }
        if (!"".equals(strGetAvg))
        {
           Double avg= Util.getDoubleValue(strGetAvg,0.00);
           if (avg>=85){
               strYybzfs="30.00";
           }else {
               strYybzfs="0.00";
           }
        }
        //基础类
        BaseBean bb = new BaseBean();
        //创建A&A+店铺流程,分发给某个人
        createWorkFlow_A(strKhzq,bb,strCreator,strJcrq,strYybzfs);
        //创建B,C,D店铺流程,分发给各个区域经理
        createWorkFlow_BCD(strKhzq,bb,strJcrq,strYybzfs);
        //createWorkFlow_BCD_New(bb,strJcrq);
    }

    /***
     * 创建店铺A和A+流程
     * @param bb
     * @param strCreator
     * @param strJcrq
     */
    public void createWorkFlow_A(String strKhzq,BaseBean bb,String strCreator,String strJcrq,String strYybzfs){
        RecordSet rs_detail_1 = new RecordSet();
        //创建流程的主表
        WorkflowRequestTableField[] wrMain = new WorkflowRequestTableField[4];
        //创建人
        log.info("申请人字段赋值：");
        wrMain[0] = new WorkflowRequestTableField();
        wrMain[0].setFieldName("sqr");
        wrMain[0].setFieldValue(strCreator);
        wrMain[0].setView(true);
        wrMain[0].setEdit(true);
        wrMain[0].setFieldOrder(0);
        wrMain[0].setMand(false);
        //创建时间
        log.info("创建日期：");
        wrMain[1] = new WorkflowRequestTableField();
        wrMain[1].setFieldName("cjsj");
        wrMain[1].setFieldValue(strJcrq);
        wrMain[1].setView(true);
        wrMain[1].setEdit(true);
        wrMain[1].setFieldOrder(0);
        wrMain[1].setMand(false);

        //店铺级别
        log.info("店铺级别：");
        wrMain[2] = new WorkflowRequestTableField();
        wrMain[2].setFieldName("dpjb");
        wrMain[2].setFieldValue("0");
        wrMain[2].setView(true);
        wrMain[2].setEdit(true);
        wrMain[2].setFieldOrder(0);
        wrMain[2].setMand(false);

        //考核周期
        log.info("考核周期：");
        wrMain[3] = new WorkflowRequestTableField();
        wrMain[3].setFieldName("khzq");
        wrMain[3].setFieldValue(strKhzq);
        wrMain[3].setView(true);
        wrMain[3].setEdit(true);
        wrMain[3].setFieldOrder(0);
        wrMain[3].setMand(false);
        //获取主表,添加配置文件，配置流程id
        String table_A = bb.getPropValue("retailExperience", "table_A");
        log.info("A/A+的明细表的值：" + table_A);
        //明细表:取所有分公司下所有店铺;
        //店铺级别dpjb：A,A+;B,C,D 店铺状态dpzt:正常，装修，闭店
        String strSqlByFgsA = "SELECT a.fgs,a.dpsapid,TO_CHAR(a.qyjl) qyjl,a.ppkdx,a.dp,a.dpjb,a.dpzt,b.departmentname FROM uf_dpxx a LEFT JOIN hrmdepartment b ON  a.DP=b.ID INNER JOIN uf_cfdplstykh c ON a.fgs=c.fgsppdy WHERE  a.dpjb IN(0,1) and a.dpzt=0 and a.dp is NOT NULL "+
                " AND EXISTS(SELECT f.departmentid FROM hrmresource f WHERE f.departmentid=a.DP) "+
                " AND NOT EXISTS(SELECT * FROM uf_yddpzxygxxd h WHERE a.FGS=h.fgs AND a.DP=h.dp AND h.khzq='"+strKhzq+"' )"+
                " AND NOT EXISTS(SELECT d.FGS,d.sapid,d.dpmc,d.dpzt,d.DPJB FROM "+table_A+" d WHERE a.FGS=d.fgs AND a.DP=d.dpmc and d.khzq='"+strKhzq+"' AND d.dpzt=a.dpzt AND d.dpjb=a.DPJB )"+
                " ORDER BY a.fgs,a.dp asc";
        rs_detail_1.executeQuery(strSqlByFgsA);
        log.info("获取店铺级别A和A+信息sql：" + strSqlByFgsA);
        //根据店铺级别封装数据,A,A+类型
        JSONArray jsonArrA = new JSONArray();
        while (rs_detail_1.next()) {
            //获取店铺级别
            String strRank = Util.null2String(rs_detail_1.getString("dpjb"));
            //根据店铺级别放入数组里
            //0:店铺级别A,1:A+;店铺级别：2:B,3:C,4:D
            JSONObject jsonObject_A = new JSONObject();
            jsonObject_A.put("dpjb", strRank);
            log.info("店铺级别：" + strRank);
            //分公司
            jsonObject_A.put("fgs", Util.null2String(rs_detail_1.getString("fgs")));
            //品牌
            String strBrand = Util.null2String(rs_detail_1.getString("ppkdx"));
            jsonObject_A.put("pp", strBrand);
            log.info("品牌：" + strBrand);
            //获取店铺状态
            String strStauts = Util.null2String(rs_detail_1.getString("dpzt"));
            jsonObject_A.put("dpzt", strStauts);
            log.info("店铺状态：" + strStauts);

            //dpmc:店铺ID
            String strDpId = Util.null2String(rs_detail_1.getString("dp"));
            jsonObject_A.put("dpmc", strDpId);
            log.info("店铺ID：" + strDpId);
            jsonObject_A.put("dpmcdr", strDpId);

            //获取店铺SAPID
            String strSAPID = Util.null2String(rs_detail_1.getString("dpsapid"));
            jsonObject_A.put("sapid", strSAPID);
            log.info("店铺SAPID：" + strSAPID);
            jsonArrA.add(jsonObject_A);
        }
        //配置流程基本信息:workflowId
        WorkflowBaseInfo wbi = new WorkflowBaseInfo();
        //获取workflowid,添加配置文件，配置流程id
        String workflowid = bb.getPropValue("retailExperience", "retailFlowId_A");
        log.info("workflowid的值：" + workflowid);
        wbi.setWorkflowId(workflowid);
        //A/A+
        if (jsonArrA != null && jsonArrA.size() > 0) {
            //填装主表相关字段对象
            WorkflowRequestTableRecord[] wrtri_A = new WorkflowRequestTableRecord[1];
            wrtri_A[0] = new WorkflowRequestTableRecord();
            wrtri_A[0].setWorkflowRequestTableFields(wrMain);
            //创建流程主表信息对象
            WorkflowMainTableInfo wmi_A = new WorkflowMainTableInfo();
            wmi_A.setRequestRecords(wrtri_A);

            WorkflowRequestInfo wrInfo = new WorkflowRequestInfo();
            wrInfo.setCreatorId("01");
            wrInfo.setRequestLevel("0");//紧急程度
            wrInfo.setRequestName("品牌-店铺零售体验考核申请流程(店长)-A");//请求的名称
            //0:停留在提交节点;1:自动流转到下一节点
            wrInfo.setIsnextflow("1");
            //主表数据
            wrInfo.setWorkflowMainTableInfo(wmi_A);
            wrInfo.setWorkflowBaseInfo(wbi);
            //明细表
            WorkflowDetailTableInfo wdti_A[] = new WorkflowDetailTableInfo[1];
            //限定明细表的长度
            wrtri_A = new WorkflowRequestTableRecord[jsonArrA.size()];
            wdti_A = getDetail(jsonArrA, wdti_A, wrtri_A,strYybzfs,strKhzq);
            wrInfo.setWorkflowDetailTableInfos(wdti_A);
            wrInfo.setCreatorId(strCreator);
            WorkflowServiceImpl wfsi_A = new WorkflowServiceImpl();
            String requestid = wfsi_A.doCreateWorkflowRequest(wrInfo, Integer.parseInt(strCreator));
            log.info("店铺零售体验考核申请A-批量生成流程返回值==" + requestid);
            if (!"".equals(requestid) && Integer.parseInt(requestid) > 0) {
                log.info("店铺A/A+流程创建成功！");
            } else {
                log.info("店铺A/A+流程创建失败！");
            }
        }
    }

    /***
     * 传统while循环方式
     * 创建店铺BCD流程
     * @param bb
     * @param strJcrq
     */
    public void createWorkFlow_BCD(String strKhzq,BaseBean bb,String strJcrq,String strYybzfs){
        RecordSet rs_qyjl_BCD = new RecordSet();
        RecordSet rs_BCD_detail =null;
        //配置流程基本信息:workflowId
        WorkflowBaseInfo wbi = new WorkflowBaseInfo();
        //获取workflowid,添加配置文件，配置流程id
        String workflowid = bb.getPropValue("retailExperience", "retailFlowId_bcd");
        log.info("workflowid的值：" + workflowid);
        wbi.setWorkflowId(workflowid);

        //1.获取店铺级别为BCD的所有区域经理
        //B,C,D类
        JSONArray jsonArrBCD = new JSONArray();
        JSONObject jsonObject_B =null;
        //获取主表,添加配置文件，配置流程id
        String table_B = bb.getPropValue("retailExperience", "table_B");
        log.info("BCD的明细表的值：" + table_B);
        String strSqlQyjl = "SELECT TO_CHAR(a.qyjl) qyjl FROM uf_dpxx a LEFT JOIN hrmdepartment b ON  a.DP=b.ID INNER JOIN uf_cfdplstykh c ON a.fgs=c.fgsppdy  WHERE a.dpjb IN(2,3,4) and a.dpzt=0 AND a.QYJL is NOT NULL GROUP BY TO_CHAR(a.qyjl)";
        rs_qyjl_BCD.executeQuery(strSqlQyjl);
        log.info("获取店铺级别B,C,D下所有区域经理sql：" + strSqlQyjl);
        while (rs_qyjl_BCD.next()) {
            rs_BCD_detail= new RecordSet();
            String strQyjl = Util.null2String(rs_qyjl_BCD.getString("qyjl"));
            //2.获取店铺级别B,C,D区域经理对应的店铺信息
            //如果流程表里有数据则剔除,取流程表中没有的数据
            String strSqlQj = "SELECT a.fgs,a.dpsapid,TO_CHAR(a.qyjl) qyjl,a.ppkdx,a.dp,a.dpjb,a.dpzt,b.departmentname FROM uf_dpxx a LEFT JOIN hrmdepartment b ON  a.DP=b.ID INNER JOIN uf_cfdplstykh c ON a.fgs=c.fgsppdy WHERE  a.dpjb IN(2,3,4) and a.dpzt=0 and TO_CHAR(a.qyjl)='" + strQyjl + "' AND a.dp is NOT NULL "+
                    " AND EXISTS(SELECT f.departmentid FROM hrmresource f WHERE f.departmentid=a.DP) "+
                    " AND NOT EXISTS(SELECT * FROM uf_yddpzxygxxd h WHERE a.FGS=h.fgs AND a.DP=h.dp AND h.khzq='"+strKhzq+"')"+
                    " AND NOT EXISTS(SELECT d.FGS,d.sapid,d.dpmc,d.dpzt,d.DPJB FROM "+table_B+" d WHERE a.FGS=d.fgs AND a.DP=d.dpmc and d.khzq='"+strKhzq+"' AND d.dpzt=a.dpzt AND d.dpjb=a.DPJB )"+
                    " ORDER BY a.fgs,a.dp asc";
            log.info("获取店铺级别B,C,D区域经理对应的店铺信息sql：" + strSqlQj);
            rs_BCD_detail.executeQuery(strSqlQj);
            while (rs_BCD_detail.next()) {
                //BCD---------------------------------------
                jsonObject_B = new JSONObject();
                String strRank = Util.null2String(rs_BCD_detail.getString("dpjb"));
                jsonObject_B.put("dpjb", strRank);
                log.info("店铺级别：" + strRank);
                //分公司
                jsonObject_B.put("fgs", Util.null2String(rs_BCD_detail.getString("fgs")));
                //品牌
                String strBrand = Util.null2String(rs_BCD_detail.getString("ppkdx"));
                jsonObject_B.put("pp", strBrand);
                log.info("品牌：" + strBrand);
                jsonObject_B.put("qyjl", strQyjl);
                log.info("区域经理：" + strQyjl);
                //获取店铺状态
                String strStauts = Util.null2String(rs_BCD_detail.getString("dpzt"));
                jsonObject_B.put("dpzt", strStauts);
                log.info("店铺状态：" + strStauts);
                //dpmc:店铺ID
                String strDpId = Util.null2String(rs_BCD_detail.getString("dp"));
                jsonObject_B.put("dpmc", strDpId);
                log.info("店铺ID：" + strDpId);
                jsonObject_B.put("dpmcdr", strDpId);

                //获取店铺SAPID
                String strSAPID = Util.null2String(rs_BCD_detail.getString("dpsapid"));
                jsonObject_B.put("sapid", strSAPID);
                log.info("店铺SAPID：" + strSAPID);

                jsonArrBCD.add(jsonObject_B);
                jsonObject_B.clear();
            }
            //判断数组是否存了明细
            if (jsonArrBCD != null && jsonArrBCD.size() > 0) {
                //创建流程的主表
                WorkflowRequestTableField[] wrMain = new WorkflowRequestTableField[4];
                //创建人
                log.info("申请人字段赋值：");
                wrMain[0] = new WorkflowRequestTableField();
                wrMain[0].setFieldName("sqr");
                wrMain[0].setFieldValue(strQyjl);
                wrMain[0].setView(true);
                wrMain[0].setEdit(true);
                wrMain[0].setFieldOrder(0);
                wrMain[0].setMand(false);
                //创建时间
                log.info("创建日期：");
                wrMain[1] = new WorkflowRequestTableField();
                wrMain[1].setFieldName("cjsj");
                wrMain[1].setFieldValue(strJcrq);
                wrMain[1].setView(true);
                wrMain[1].setEdit(true);
                wrMain[1].setFieldOrder(0);
                wrMain[1].setMand(false);
                //店铺级别
                log.info("店铺级别：");
                wrMain[2] = new WorkflowRequestTableField();
                wrMain[2].setFieldName("dpjb");
                wrMain[2].setFieldValue("1");
                wrMain[2].setView(true);
                wrMain[2].setEdit(true);
                wrMain[2].setFieldOrder(0);
                wrMain[2].setMand(false);

                //考核周期
                log.info("考核周期：");
                wrMain[3] = new WorkflowRequestTableField();
                wrMain[3].setFieldName("khzq");
                wrMain[3].setFieldValue(strKhzq);
                wrMain[3].setView(true);
                wrMain[3].setEdit(true);
                wrMain[3].setFieldOrder(0);
                wrMain[3].setMand(false);

                //填装主表相关字段对象
                WorkflowRequestTableRecord[] wrtri_bcd = new WorkflowRequestTableRecord[1];
                wrtri_bcd[0] = new WorkflowRequestTableRecord();
                wrtri_bcd[0].setWorkflowRequestTableFields(wrMain);
                //创建流程主表信息对象
                WorkflowMainTableInfo wmi_bcd = new WorkflowMainTableInfo();
                wmi_bcd.setRequestRecords(wrtri_bcd);
                WorkflowRequestInfo wrInfo_bcd = new WorkflowRequestInfo();
                wrInfo_bcd.setCreatorId("01");
                wrInfo_bcd.setRequestLevel("0");//紧急程度
                wrInfo_bcd.setRequestName("品牌-店铺零售体验考核申请流程(店长)-BCD");//请求的名称
                //停留在提交节点
                wrInfo_bcd.setIsnextflow("1");
                //主表数据
                wrInfo_bcd.setWorkflowMainTableInfo(wmi_bcd);
                wrInfo_bcd.setWorkflowBaseInfo(wbi);
                //明细表
                WorkflowDetailTableInfo wdti_bcd[] = new WorkflowDetailTableInfo[1];
                //限定明细表的长度
                wrtri_bcd = new WorkflowRequestTableRecord[jsonArrBCD.size()];
                wdti_bcd = getDetail(jsonArrBCD, wdti_bcd, wrtri_bcd,strYybzfs,strKhzq);
                log.info("店铺BCD明细取数成功,绑定到流程数组中");
                wrInfo_bcd.setWorkflowDetailTableInfos(wdti_bcd);
                wrInfo_bcd.setCreatorId(strQyjl);
                WorkflowServiceImpl wfsi_bcd = new WorkflowServiceImpl();
                String requestid = wfsi_bcd.doCreateWorkflowRequest(wrInfo_bcd, Integer.parseInt(strQyjl));
                log.info("店铺零售体验考核申请BCD-批量生成流程返回值==" + requestid);
                if (!"".equals(requestid) && Integer.parseInt(requestid) > 0) {
                    log.info("店铺BCD流程创建成功！");
                } else {
                    log.info("店铺BCD流程创建失败！");
                }
            }
            jsonArrBCD.clear();//清空
        }

    }

    /***
     * for循环遍历集合实现,比传统方法只快了1S.......
     * 创建店铺BCD流程
     * @param bb
     * @param strJcrq
     */
    public void createWorkFlow_BCD_New(BaseBean bb,String strJcrq,String strYybzfs,String strkhzq){
        RecordSet rs_qyjl_BCD = new RecordSet();
        RecordSet rs_BCD_detail =null;
        //配置流程基本信息:workflowId
        WorkflowBaseInfo wbi = new WorkflowBaseInfo();
        //获取workflowid,添加配置文件，配置流程id
        String workflowid = bb.getPropValue("retailExperience", "retailFlowId");
        log.info("workflowid的值：" + workflowid);
        wbi.setWorkflowId(workflowid);

        //1.获取店铺级别为BCD的所有区域经理
        //B,C,D类
        JSONArray jsonArrBCD = new JSONArray();
        JSONObject jsonObject_B =null;
        dpxxRepositoryImpl dpxx=new dpxxRepositoryImpl();
        List<dpxxVo> dpxxList = dpxx.getDpxxList();
        log.info("遍历店铺信息表集合：");
        for (dpxxVo dpxxVo : dpxxList) {
            String strQyjl =dpxxVo.getQyjl();
            log.info("获取区域经理：" + strQyjl);
            List<dpxxInfo> dpxxList1 = dpxxVo.getDpxxList();
            for (dpxxInfo dpxxInfo : dpxxList1) {
                log.info("获取区域经理负责所属店铺的店铺信息：" + dpxxInfo.toString());
                jsonObject_B = new JSONObject();
                //店铺级别
                String strRank =dpxxInfo.getDpjb();
                jsonObject_B.put("dpjb", strRank);
                //分公司
                String strFgs=dpxxInfo.getFgs();
                jsonObject_B.put("fgs", strFgs);
                //品牌
                String strBrand=dpxxInfo.getPpkdx();
                jsonObject_B.put("pp", strBrand);
                //店铺状态
                String strStauts=dpxxInfo.getDpzt();
                jsonObject_B.put("dpzt", strStauts);
                //店铺
                String strDpId=dpxxInfo.getDp();
                jsonObject_B.put("dpmc", strDpId);
                jsonObject_B.put("dpmcdr", strDpId);
                jsonArrBCD.add(jsonObject_B);
                jsonObject_B.clear();
            }
            //判断数组是否存了明细
            if (jsonArrBCD != null && jsonArrBCD.size() > 0) {
                //创建流程的主表
                WorkflowRequestTableField[] wrMain = new WorkflowRequestTableField[4];
                //创建人
                log.info("申请人字段赋值：");
                wrMain[0] = new WorkflowRequestTableField();
                wrMain[0].setFieldName("sqr");
                wrMain[0].setFieldValue(strQyjl);
                wrMain[0].setView(true);
                wrMain[0].setEdit(true);
                wrMain[0].setFieldOrder(0);
                wrMain[0].setMand(false);
                //创建时间
                log.info("创建日期：");
                wrMain[1] = new WorkflowRequestTableField();
                wrMain[1].setFieldName("cjsj");
                wrMain[1].setFieldValue(strJcrq);
                wrMain[1].setView(true);
                wrMain[1].setEdit(true);
                wrMain[1].setFieldOrder(0);
                wrMain[1].setMand(false);
                //店铺级别
                log.info("店铺级别：");
                wrMain[2] = new WorkflowRequestTableField();
                wrMain[2].setFieldName("dpjb");
                wrMain[2].setFieldValue("1");
                wrMain[2].setView(true);
                wrMain[2].setEdit(true);
                wrMain[2].setFieldOrder(0);
                wrMain[2].setMand(false);

                //考核周期
                log.info("考核周期：");
                wrMain[3] = new WorkflowRequestTableField();
                wrMain[3].setFieldName("khzq");
                wrMain[3].setFieldValue(strkhzq);
                wrMain[3].setView(true);
                wrMain[3].setEdit(true);
                wrMain[3].setFieldOrder(0);
                wrMain[3].setMand(false);

                //填装主表相关字段对象
                WorkflowRequestTableRecord[] wrtri_bcd = new WorkflowRequestTableRecord[1];
                wrtri_bcd[0] = new WorkflowRequestTableRecord();
                wrtri_bcd[0].setWorkflowRequestTableFields(wrMain);
                //创建流程主表信息对象
                WorkflowMainTableInfo wmi_bcd = new WorkflowMainTableInfo();
                wmi_bcd.setRequestRecords(wrtri_bcd);
                WorkflowRequestInfo wrInfo_bcd = new WorkflowRequestInfo();
                wrInfo_bcd.setCreatorId("01");
                wrInfo_bcd.setRequestLevel("0");//紧急程度
                wrInfo_bcd.setRequestName("品牌-店铺零售体验考核申请流程(店长)-BCD");//请求的名称
                //停留在提交节点
                wrInfo_bcd.setIsnextflow("1");
                //主表数据
                wrInfo_bcd.setWorkflowMainTableInfo(wmi_bcd);
                wrInfo_bcd.setWorkflowBaseInfo(wbi);
                //明细表
                WorkflowDetailTableInfo wdti_bcd[] = new WorkflowDetailTableInfo[1];
                //限定明细表的长度
                wrtri_bcd = new WorkflowRequestTableRecord[jsonArrBCD.size()];
                wdti_bcd = getDetail(jsonArrBCD, wdti_bcd, wrtri_bcd,strYybzfs,strkhzq);
                log.info("店铺BCD明细取数成功,绑定到流程数组中");
                wrInfo_bcd.setWorkflowDetailTableInfos(wdti_bcd);
                wrInfo_bcd.setCreatorId(strQyjl);
                WorkflowServiceImpl wfsi_bcd = new WorkflowServiceImpl();
                String requestid = wfsi_bcd.doCreateWorkflowRequest(wrInfo_bcd, Integer.parseInt(strQyjl));
                log.info("店铺零售体验考核申请BCD-批量生成流程返回值==" + requestid);
                if (!"".equals(requestid) && Integer.parseInt(requestid) > 0) {
                    log.info("店铺BCD流程创建成功！");
                } else {
                    log.info("店铺BCD流程创建失败！");
                }
            }
            jsonArrBCD.clear();
        }

    }

    /**
     * 封装明细数据
     */

    public WorkflowDetailTableInfo[] getDetail(JSONArray jsonArray, WorkflowDetailTableInfo[] wdti, WorkflowRequestTableRecord[] wrtri,String strYybzfs,String strkhzq) {
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        String strJcrq = df.format(new Date());
        for (int i = 0; i < jsonArray.size(); i++) {

            JSONObject jsonObject = jsonArray.getJSONObject(i);
            log.info("封装明细json:" + jsonObject);
            try {
                WorkflowRequestTableField[] wrti = new WorkflowRequestTableField[15];
                wrti[0] = new WorkflowRequestTableField();
                wrti[0].setFieldName("fgs");
                wrti[0].setFieldValue(jsonObject.getString("fgs"));
                wrti[0].setView(true);
                wrti[0].setEdit(true);

                wrti[1] = new WorkflowRequestTableField();
                wrti[1].setFieldName("dpmc");
                wrti[1].setFieldValue(jsonObject.getString("dpmc"));
                wrti[1].setView(true);
                wrti[1].setEdit(true);

                wrti[2] = new WorkflowRequestTableField();
                wrti[2].setFieldName("dpmcdr");
                wrti[2].setFieldValue(jsonObject.getString("dpmcdr"));
                wrti[2].setView(true);
                wrti[2].setEdit(true);

                wrti[3] = new WorkflowRequestTableField();
                wrti[3].setFieldName("dpzt");
                wrti[3].setFieldValue(jsonObject.getString("dpzt"));
                wrti[3].setView(true);
                wrti[3].setEdit(true);

                wrti[4] = new WorkflowRequestTableField();
                wrti[4].setFieldName("dpjb");
                wrti[4].setFieldValue(jsonObject.getString("dpjb"));
                wrti[4].setView(true);
                wrti[4].setEdit(true);

                wrti[5] = new WorkflowRequestTableField();
                wrti[5].setFieldName("pp");
                wrti[5].setFieldValue(jsonObject.getString("pp"));
                wrti[5].setView(true);
                wrti[5].setEdit(true);

                wrti[6] = new WorkflowRequestTableField();
                wrti[6].setFieldName("fwbz40");
                wrti[6].setView(true);
                wrti[6].setEdit(true);
                wrti[7] = new WorkflowRequestTableField();
                wrti[7].setFieldName("clbz20");
                wrti[7].setView(true);
                wrti[7].setEdit(true);
                wrti[8] = new WorkflowRequestTableField();
                wrti[8].setFieldName("yybz35");
                wrti[8].setFieldValue(strYybzfs);
                wrti[8].setView(true);
                wrti[8].setEdit(true);

                wrti[9] = new WorkflowRequestTableField();
                wrti[9].setFieldName("crm5");
                wrti[9].setView(true);
                wrti[9].setEdit(true);

                wrti[10] = new WorkflowRequestTableField();
                wrti[10].setFieldName("zdf");
                wrti[10].setView(true);
                wrti[10].setEdit(true);

                wrti[11] = new WorkflowRequestTableField();
                wrti[11].setFieldName("khrq");
                wrti[11].setFieldValue(strJcrq);
                wrti[11].setView(true);
                wrti[11].setEdit(true);

                wrti[12] = new WorkflowRequestTableField();
                wrti[12].setFieldName("khzq");
                wrti[12].setFieldValue(strkhzq);
                wrti[12].setView(true);
                wrti[12].setEdit(true);

                wrti[13] = new WorkflowRequestTableField();
                wrti[13].setFieldName("sapid");
                wrti[13].setFieldValue(jsonObject.getString("sapid"));
                wrti[13].setView(true);
                wrti[13].setEdit(true);

                wrti[14] = new WorkflowRequestTableField();
                wrti[14].setFieldName("sapiddr");
                wrti[14].setFieldValue(jsonObject.getString("sapid"));
                wrti[14].setView(true);
                wrti[14].setEdit(true);

                wrtri[i] = new WorkflowRequestTableRecord();
                wrtri[i].setWorkflowRequestTableFields(wrti);
            } catch (Exception ex) {
                log.info("封装明细表数据出现异常,异常信息：" + ex.toString());
            }


        }
        wdti[0] = new WorkflowDetailTableInfo();
        wdti[0].setWorkflowRequestTableRecords(wrtri);
        return wdti;

    }

}
